package controllers;

import helpers.UrlHelper;

import java.io.IOException;
import java.util.TreeMap;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import admin.models.MetaSeoModel;

import systems.ConfigSystem;
import entities.MetaSeo;
import entities.SiteConfig;

public class CheckWhoisServlet extends HttpServlet {
	public void doGet(HttpServletRequest request, HttpServletResponse response)
		throws IOException, ServletException {
		
		SiteConfig siteConfig = ConfigSystem.getConfigs();
		
		TreeMap<String, String> check = new TreeMap<String, String>();
		String name = (String) request.getParameter("domain");
		
		if (name == null || !UrlHelper.checkDomain(name)) {
			check.put("name", "Please provice your domain.");
		} else {
			name = UrlHelper.getMainDomain(name);
		} 
		
		//Set seo content
        MetaSeoModel metaseoModel = MetaSeoModel.getInstance();
        MetaSeo metaseo = metaseoModel.get("whois");
		
		//Cache header
		response.addHeader("Cache-Control", "public, max-age=60000");
		
		request.setAttribute("name", name);
		request.setAttribute("metaseo", metaseo);
		try {
			request.getRequestDispatcher("/pages/check_whois.jsp").forward(request, response);
		} catch (ServletException e) {
			e.printStackTrace();
		}
	}
}
